// pages/activity/vote/rank/rank.js
let utilApp = require('../../../../utils/app');
const { regeneratorRuntime } = global;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    site:'',
    sum:0,
    daminggong:0,
    shiboyuan:0,
    dayanta:0,
    kunminghu:0,
    sharePop:false
  },
  popHide(){
    this.setData({
      sharePop:false
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: async function () {
    let plantAddArr=["大明宫", "大雁塔", "昆明湖", "世博园"];
    let userInfo = wx.getStorageSync('userInfo');
    let site = await utilApp.doPost('Area/isChoose', { openId: userInfo.openId });
    this.setData({
      site: plantAddArr[site.data.area-1]
    })
    let areaRanking = await utilApp.doPost('Area/areaRanking', { openId: userInfo.openId });
    let arr = areaRanking.data.rand;
    console.log(areaRanking.data.rand)
    let sum =0;
    for ( let i=0;i<arr.length;i++){
      sum+=parseInt(arr[i].counts)
      if (arr[i].area==1){
        this.setData({
          daminggong: arr[0].counts,
        })
      } else if (arr[i].area == 2){
        this.setData({
          dayanta: arr[i].counts,
        })
      } else if (arr[i].area == 3){
        this.setData({
          kunminghu: arr[i].counts,
        })
      } else if (arr[i].area == 4){
        this.setData({
          shiboyuan: arr[i].counts,
        })
      }
    }
    this.setData({
      sum
    })

  },
  rankingBtn(){
    this.setData({
      sharePop:true
    })
  },
  sharePengYouQuan(){
    let that = this;
    that.setData({
      sharePop: false
    })
    utilApp.showModal('提示','功能即将上线','确定',function(){},function(){},false)
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (ops) {
    let that = this;
    that.setData({
      sharePop: false
    })
    if (ops.from === 'button') {
      // 来自页面内转发按钮 
      console.log(ops.target)
    }
    return {
      title: '西安移动投票赢话费',
      path: 'pages/activity/vote/index/index',
      imageUrl: '../../../../image/index-bottom.jpg',
      success: function (res) {
        // 转发成功
        wx.showToast({
          title: '转发成功',
        })
      },
      fail: function (res) {
        utilApp.showErr('分享失败', 2000)
      }
    }
  }
})